﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading;
using Micua.Core.Caching.Interception;
using Micua.Core.Configuration;
using Micua.Core.IoC;
using Micua.Core.Mail;
using Micua.Utility;

namespace Micua.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            //System.Console.WriteLine(ApplicationHelper.MapPath("~/config/micua.config"));

            //while (true)
            //{
            //    var conf1 = ConfigHelper.GetString("SiteRoot");
            //    System.Console.WriteLine(conf1);
            //    var conf2 = ConfigHelper.GetString("UploadAllowType");
            //    System.Console.WriteLine(conf2);
            //    var conf3 = ConfigHelper.GetString("conf3");
            //    System.Console.WriteLine(conf3);

            //    System.Console.WriteLine(DateTime.Now);
            //    Thread.Sleep(5000);
            //}


            //var dict = new Dictionary<string, string>();
            //for (int i = 0; i < 10; i++)
            //{
            //    StringBuilder sb = new StringBuilder(10);
            //    for (int j = 0; j < 10; j++)
            //    {
            //        sb.Append(i);
            //    }
            //    dict.Add("conf" + i, sb.ToString());
            //}
            //var json = JsonHelper.Serialize(dict);
            //var xml = XmlHelper.Serialize(dict);

            //var dict = new Dictionary<string, string> 
            //{ 
            //    { "smtp_server","smtp.wedn.net"},
            //    {"smtp_server_PORT","25"}
            //};
            //Setting.Init(dict);
            //SmtpHelper.Send(new[] { "ice@wedn.net" }, "测试发送邮件", "<h1>这是一封测试邮件</h1>", ccs: new string[] { "379144367@qq.com" }, bccs: new string[] { "27102514@qq.com" }, priority: MailPriority.High, attachments: new Attachment("d://config.xml"));



            //初始化IoC
            IoCHelper.InitializeWith(new DependencyResolverFactory());

            var service = IoCHelper.Resolve<IPostService>();

            if (service != null)
            {
                while (true)
                {
                    System.Console.WriteLine(service.GetNow());
                    Thread.Sleep(2000);
                }
            }

            //var service2 = IoCHelper.Resolve<IPostService>();

            //for (int i = 0; i < 5; i++)
            //{
            //    System.Console.WriteLine(service.GetAge());
            //}
            //for (int i = 0; i < 5; i++)
            //{
            //    System.Console.WriteLine(service2.GetAge());
            //}
            System.Console.ReadKey();
        }
    }

    public interface IPostService
    {
        DateTime GetNow();
        int GetAge();
    }

    public class PostService : IPostService
    {
        [CachingCallResult(4)]
        public DateTime GetNow()
        {
            return DateTime.Now;
        }

        private int age = 1;
        public int GetAge()
        {
            return age++;
        }
    }
}
